/*
Copyright (C) 2010-2011 Sylvain Martin (Spintec - CEA/CNRS/UJF/G-INP)
All rights reserved.

This file is part of the SpinToolBox project

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#pragma once

#ifndef SPLOT2D_H
#define SPLOT2D_H

#include "SPlot2DWidget.h"
#include "SPlotCurveData.h"
#include "../SData/SData2D.h"
#include <QScriptable>
#include <QScriptValue>
#include <QScriptEngine>

#include <QMainWindow>
#include <QList>

#include <QToolBar>
#include <QToolButton>
#include <QAction>

#include <qwt_plot_curve.h>
#include <qwt_data.h>
#include <qwt_array.h>
#include <qwt_plot.h>



////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class	SPlot2D
///
/// \brief	define a Main windows that contained a 2D Plot with all the basic tool (zoom, ...).
///
/// \author	Sylvain Martin
/// \date	2/4/2011
///
/// \remark order to use Qwt as a dll and inherit a QWT object we must define the macro in the
/// 		preprocessor QWT_DLL. in , the project need a preprocessor define
/// 		[configuration properties]->[c/c++]->[preprocessor]->[preprocessor definitions]-> QWT_DLL
/// 		(and leave the rest as it is)
///
/// \sa SPlot2DWidget
///
/// contained a sub-class of QwtPlot that has some new functions, like a \c zoom, an \c autoscale
/// and a way to chose a scale (\c selectScale).
////////////////////////////////////////////////////////////////////////////////////////////////////
class SPlot2D : public QMainWindow  , protected QScriptable
{
	Q_OBJECT

public:
	SPlot2D(QWidget *parent = 0);
	SPlot2D(SData2D *data, bool overbookDefault = true ,QWidget *parent = 0);
	SPlot2DWidget * plot2DWidget();

	Q_INVOKABLE void setData(SData2D  *data, int curveNb=0);
	Q_INVOKABLE void setData(SData2D  data, int curveNb=0);
	Q_INVOKABLE void addData(double  x, double  y, int const curveNb=0);
	Q_INVOKABLE void append(double  x, double  y, int const curveNb=0); 
	Q_INVOKABLE void clearData(int curveNb =0);

	Q_INVOKABLE void setTitle(QString title, int curveNb=0);
	Q_INVOKABLE QString title(int curveNb =0);
	Q_INVOKABLE void setColor( QString name, int curveNb =0);

	Q_INVOKABLE bool overbook(int curveNb =0) const;
	Q_INVOKABLE void setOverbook(bool val, int curveNb =0);

	Q_INVOKABLE bool overbookDefault() const;
	Q_INVOKABLE void setOverbookDefault(bool val);

	void addData(double  *x, double  *y, int const size, int const curveNb);
	static QScriptValue qsCtor(QScriptContext *context, QScriptEngine *engine);

	~SPlot2D();
public slots:
		void zoom();
		void autoScale();
		void selectScale();
		void setScale(double Xmin, double Xmax, double Ymin, double Ymax);

private:
	void setupUI();

	SPlot2DWidget * plot2D_;
	QList<QwtPlotCurve*> curveList_;
	QwtPlotCurve * plot1;
	QList<SPlotCurveData *> dataList_;

	QAction * actZoom;
	QAction * actAutoScale;
	QAction * actSetScale;
	QAction * actMarker;
	QAction * actSelectData;
	QToolBar *toolBar;

	bool overbookDefault_;



};

Q_DECLARE_METATYPE(SPlot2D*);



#endif // SPLOT2D_H